--[[
--函数2:lua_video_set_progress
-- 设置progress,并更新duration字段(当前时间减去start_time),当progress为100时将state更新为生成成功
--参数:ARGV[1]:doc_id:23
--参数:ARGV[2]:progress: 20 (状态:1生成中,2生成失败,3生成成功)
--参数:ARGV[3]:current_time: "时间戳" (状态:1生成中,2生成失败,3生成成功)
--返回: 0表示成功,1表示失败
-- ]]--

local PREFIX_DOC = "doc_id_"
local key = PREFIX_DOC..ARGV[1]
--设置progress
redis.call("hset",key,"progress",ARGV[2])
--计算duration
local time = redis.call("hget",key,"start_time")
local start_time = tonumber(time) or 0
--转当前时间戳单位(秒)
local current_time = tonumber(ARGV[3]) or 0
local duration = current_time - start_time
if(duration<0)
then
    return 1
end
redis.call("hset",key,"duration",duration)
local progress = tonumber(ARGV[2]) or 0
--当progress为100时将state更新为3生产成功
if(progress == 100)
then
    redis.call("hset",key,"state",3)
end

return 0
